/*
 *    Copyright (c) 2018-2025, fanxl All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: fanxl (xunlian_fan001@126.com)
 */

package com.taiji.dicom4cloud.smart.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.util.StringUtil;
import com.taiji.dicom4cloud.common.core.utils.CommonUtils;
import com.taiji.dicom4cloud.common.core.utils.R;
import com.taiji.dicom4cloud.common.log.annotation.SnowLog;
import com.taiji.dicom4cloud.smart.model.entity.AlarmEquipment;
import com.taiji.dicom4cloud.smart.model.entity.Camera;
import com.taiji.dicom4cloud.smart.service.AlarmEquipmentService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author fanxl
 * @date 2021-07-06 10:47:47
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/alarmequipment" )
@Api(value = "alarmequipment", tags = "管理")
public class AlarmEquipmentController {

    private final AlarmEquipmentService alarmEquipmentService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param alarmEquipment 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getAlarmEquipmentPage(Page page, AlarmEquipment alarmEquipment) {
        return R.ok(alarmEquipmentService.page(page, Wrappers.<AlarmEquipment>lambdaQuery()
                .like(StringUtil.isNotEmpty(alarmEquipment.getAlarmEquipmentName()),AlarmEquipment::getAlarmEquipmentName,alarmEquipment.getAlarmEquipmentName())
        .like(StringUtil.isNotEmpty(alarmEquipment.getAlarmEquipmentCode()),AlarmEquipment::getAlarmEquipmentCode,alarmEquipment.getAlarmEquipmentCode())));
    }

    @ApiOperation(value = "查询所有设备列表", notes = "查询所有设备列表")
    @GetMapping("/all" )
    public R getRfidEquipmentAll(String orgId){
        return R.ok(alarmEquipmentService.list(Wrappers.<AlarmEquipment>lambdaQuery()
                .eq(AlarmEquipment::getDelFalg,"0")
                .eq(StringUtil.isNotEmpty(orgId)&&!orgId.equals("-1"),
                        AlarmEquipment::getOrgId,orgId)
        ));
    }

    /**
     * 通过id查询
     * @param equipmentId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{equipmentId}" )
//    @PreAuthorize("@pms.hasPermission('alarmEquipment_alarmequipment_get')" )
    public R getById(@PathVariable("equipmentId" ) String equipmentId) {
        return R.ok(alarmEquipmentService.getOne(Wrappers.<AlarmEquipment>lambdaQuery()
                .eq(AlarmEquipment::getEquipmentId,equipmentId)));
    }

    /**
     * 新增
     * @param alarmEquipment 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SnowLog("新增" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('alarmEquipment_alarmequipment_add')" )
    public R save(@RequestBody AlarmEquipment alarmEquipment) {
        alarmEquipment.setAlarmEquipmentId(CommonUtils.getUUID());
        return R.ok(alarmEquipmentService.save(alarmEquipment));
    }

    /**
     * 修改
     * @param alarmEquipment 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SnowLog("修改" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('alarmEquipment_alarmequipment_edit')" )
    public R updateById(@RequestBody AlarmEquipment alarmEquipment) {
        return R.ok(alarmEquipmentService.updateById(alarmEquipment));
    }

    /**
     * 通过id删除
     * @param alarmEquipmentId id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SnowLog("通过id删除" )
    @DeleteMapping("/{alarmEquipmentId}" )
//    @PreAuthorize("@pms.hasPermission('alarmEquipment_alarmequipment_del')" )
    public R removeById(@PathVariable String alarmEquipmentId) {
        return R.ok(alarmEquipmentService.removeById(alarmEquipmentId));
    }

}
